//
//  NetWorkTools.swift
//  ZYBWeibo
//
//  Created by xthink4 on 16/3/11.
//  Copyright © 2016年 zyb. All rights reserved.
//

import UIKit
import Alamofire
import SVProgressHUD
///抽取网络框架
class NetWorkTools: NSObject {

    class func requestJSON(method:Alamofire.Method,urlString:String,parameters: [String: AnyObject]? = nil,completion:(JSON:AnyObject?)->Void){
        SVProgressHUD.show()
        Alamofire.request(method, urlString,parameters:parameters).responseJSON { (Response) -> Void in
            
            let json=Response.result.value
            let error=Response.result.error
            //出错处理
            if json == nil || error != nil{
                SVProgressHUD.showInfoWithStatus("网络出错！")
                print("ERROR JSON:\(json) error:\(error)")
                completion(JSON: nil)
                return
            }
            completion(JSON: json)
        }
    }
}
